package com.qkl.xiatang.app.jobs;


import com.qkl.xiatang.app.service.impl.AppThreadPoolService;
import com.qkl.xiatang.app.service.impl.FeedNoticeService;
import com.qkl.xiatang.app.service.redis.LockService;
import com.qkl.xiatang.app.utils.AppUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


@Component
@EnableScheduling
@Slf4j
public class AppJob {

    @Autowired
    private FeedNoticeService feedNoticeService;

    @Autowired
    private LockService lockService;

    @Autowired
    private AppThreadPoolService appThreadPool;


    /**
     * 未喂料提醒通知 7 分钟执行一次
     */
    @Scheduled(cron = "0 0/7 * * * ?")
    public void unfeededNotice(){
        String lockKey = "unfeededNotice";
        String lockValue = AppUtils.genIdStr();
        boolean lock = lockService.lockJobs(lockKey,lockValue);
        if(lock) {
            log.info("========job unfeededNotice start run.开始运行");
            appThreadPool.execute(()->{
                feedNoticeService.unfeededNotice(7);
            });
            //lockService.releaseLock(lockKey,lockValue);
            //log.info("========job unfeededNotice end run.结束运行");
        }
    }

}
